import request from '@/utils/request';

// 查询客户列表
export function listCustomer(query) {
  return request({
    url: '/system/customer/list',
    method: 'get',
    params: query
  });
}

// 查询客户详情
export function getCustomer(customerId) {
  return request({
    url: '/system/customer/' + customerId,
    method: 'get'
  });
}

// 新增客户
export function addCustomer(data) {
  return request({
    url: '/system/customer',
    method: 'post',
    data: data
  });
}

// 修改客户
export function updateCustomer(data) {
  return request({
    url: '/system/customer',
    method: 'put',
    data: data
  });
}

// 删除客户
export function delCustomer(customerId) {
  return request({
    url: '/system/customer/' + customerId,
    method: 'delete'
  });
}

// 查询客户订单列表
export function listOrderCustomer(query) {
  return request({
    url: '/system/order/customer/list',
    method: 'get',
    params: query
  });
}

// 查询客户订单统计
export function getCustomerOrderCount(customerId) {
  return request({
    url: '/system/order/customer/list/statistics',
    method: 'get',
    params: { customerId }
  });
}

// 修改用户绑定的业务员
export function updateCustomerSalesman(data) {
  return request({
    url: '/system/customer/salesman',
    method: 'post',
    data: data
  });
}

// 查询未分配的客户列表
export function listUnassignedCustomer(query) {
  return request({
    url: '/system/customer/list',
    method: 'get',
    params: {
      ...query,
      pageSize: 100,
      pageNum: 1,
      isAllocatedSalesman: '0'
    }
  });
}

// 客户置顶
export function topCustomer(data) {
  return request({
    url: '/system/customer/top',
    method: 'post',
    data: data
  });
}
